/*
 * @Author       : Hejh(3010733382@qq.com)
 * @Version      : V1.0
 * @Date         : 2024-03-10 22:30:03
 * @Description  : 一些通用的下拉菜单选项
 */

import { navTypeList } from '@/constants/explorer'
import { PERMISSIONS } from '@/constants/permission'
import type { IndexObj } from '@/types/commom'

// 新建文件类型下拉菜单
export const newFileActions = [
  {
    label: 'txt文件',
    key: 'new.txt',
    myIcon: 'wenjianleixing-biaozhuntu-jishiben'
  },
  {
    label: 'md文件',
    key: 'new.md',
    myIcon: 'tongyong_MDwenjian'
  },
  {
    label: 'html文件',
    key: 'new.html',
    myIcon: 'chrome'
  },
  {
    key: 'd1',
    type: 'divider'
  },
  {
    label: 'Word docx文件',
    key: 'new.docx',
    myIcon: 'wenjianleixing-biaozhuntu-Wordwendang'
  },
  {
    label: 'Excel xlsx文件',
    key: 'new.xlsx',
    myIcon: 'wenjianleixing-biaozhuntu-gongzuobiao'
  },
  {
    label: 'PowerPoint pptx文件',
    key: 'new.pptx',
    myIcon: 'wenjianleixing-biaozhuntu-huandengpian'
  }
]

// 上传文件下拉菜单
export const uploadActions = [
  {
    label: '上传文件',
    key: 'upload.file',
    myIcon: 'xiazaijiantou-copy'
  },
  {
    label: '上传文件夹',
    key: 'upload.folder',
    myIcon: 'xiazaijiantou-copy'
  }
]

export const DropDownType = {
  SOURCE_OUT: 'source-out', //文件导航下的空白区域
  SOURCE: 'source', // 文件列表项
  TREE_SOURCE: 'tree-source', // 文件侧边树形
  TREE_SHARETO: 'tree-shareTo', //,我的协作侧边树形
  SHARETO_OUT: 'shareTo-out', //,我的协作空白区域
  SHARETO_SOURCE: 'shareTo-source', //我的协作source列表项
  TREE_LINK: 'tree-link', //,我的分享侧边树形
  LINK_SOURCE: 'link-source', //我的分享source列表项
  LINK_OUT: 'link-out', //我的分享空白区域
  TREE_BIN: 'tree-bin', //回收站侧边树形
  BIN_SOURCE: 'bin-source', //回收站列表项
  BIN_OUT: 'bin-out', //回收站列表区域
  FILE_TYPE_SOURCE: 'file-type-source', //文件类型列表项
  FILE_TYPE_OUT: 'file-type-out', //文件类型导航下的空白区域
  TREE_FILE_TYPE: 'tree-file-type', //文件类型侧边树形
  TREE_DEP: 'tree-dep', // 部门侧边树形
  DEP_SOURCE: 'dep-source', // 部门列表项
  DEP_OUT: 'dep-out',
  SOURCE_ACTIONS: 'source-action',
  HAS_CUT: 'has-cut', // 需要剪切版,
  TREE_LINK_DESC: 'tree-link-desc',
  LINK_DESC: 'link-desc',
  LINK_DESC_OUT: 'link-desc-out'
}

/**
 * source-out 文件导航下的空白区域
 * file-type-out：文件类型导航下的空白区域
 * tree-file-type：文件类型侧边树形
 * tree-bin:回收站侧边树形
 * tree-shareTo :我的协作侧边树形
 * tree-link: 我的分享侧边树形
 * shareTo-out :我的协作空白区域
 * shareTo-source:我的协作source列表项
 * link-source:我的分享source列表项
 * link-out:我的分享空白区域
 * bin-source:回收站列表项
 * bin-out:回收站列表区域
 * file-type-source:文件类型列表项
 */

/**
 * 禁用选项，需要source item项类型
 * len-1 选中项为1
 * len-more 选中项为多
 */

interface ContextMenuType {
  label?: string
  key: string
  myIcon?: string
  type?: string
  range?: string[]
  auth?: any
  children?: IndexObj[]
  needKey?: string[]
}

export const contextMenus: ContextMenuType[] = [
  {
    label: '刷新',
    key: 'reflesh',
    myIcon: 'shuaxin2',
    range: [
      DropDownType.BIN_OUT,
      DropDownType.FILE_TYPE_OUT,
      DropDownType.SHARETO_OUT,
      DropDownType.LINK_OUT,
      DropDownType.SOURCE_OUT,
      DropDownType.LINK_DESC_OUT
    ]
  },
  {
    label: '刷新树目录',
    key: 'reflesh-tree',
    myIcon: 'shuaxin2',
    range: [DropDownType.TREE_SOURCE, DropDownType.TREE_LINK_DESC]
  },
  {
    type: 'divider',
    key: 'd1',
    needKey: ['reflesh', 'reflesh-tree']
  },
  {
    label: '打开',
    key: 'open',
    myIcon: 'dakaiwenjian-',
    range: [
      DropDownType.TREE_FILE_TYPE,
      DropDownType.TREE_SHARETO,
      DropDownType.TREE_LINK,
      DropDownType.TREE_BIN,
      DropDownType.SHARETO_SOURCE,
      DropDownType.FILE_TYPE_SOURCE,
      DropDownType.SOURCE,
      DropDownType.LINK_DESC
    ],
    auth: {
      other: ['len-1']
    }
  },
  {
    type: 'divider',
    key: 'd2',
    needKey: ['open']
  },
  {
    label: '上传文件',
    key: 'upload',
    myIcon: 'xiazaijiantou-copy',
    range: [DropDownType.SOURCE_OUT],
    auth: {
      role: [PERMISSIONS.SOURCE_UPLOAD],
      doc: [PERMISSIONS.DOC_UPLOAD]
    }
  },
  {
    label: '新建文件夹',
    key: 'createDir',
    myIcon: 'wenjianjia2',
    range: [DropDownType.SOURCE_OUT, DropDownType.TREE_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_ADD],
      doc: [PERMISSIONS.DOC_EDIT]
    }
  },
  {
    label: '新建文件',
    key: 'createSource',
    myIcon: 'xinjianwenjian',
    range: [DropDownType.SOURCE_OUT, DropDownType.TREE_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_ADD],
      doc: [PERMISSIONS.DOC_EDIT]
    },
    children: newFileActions
  },
  {
    label: '粘贴',
    key: 'paste',
    myIcon: 'niantie1',
    range: [DropDownType.SOURCE_OUT, DropDownType.TREE_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_EDIT],
      doc: [PERMISSIONS.DOC_EDIT],
      other: ['cut-exist']
    }
  },
  {
    type: 'divider',
    key: 'd3',
    needKey: ['upload', 'createDir', 'createSource', 'paste']
  },
  {
    label: '下载',
    key: 'download',
    myIcon: 'xiazaijiantou',
    range: [
      DropDownType.SOURCE,
      DropDownType.TREE_SOURCE,
      DropDownType.LINK_DESC,
      DropDownType.TREE_LINK_DESC,
      DropDownType.FILE_TYPE_SOURCE
    ],
    auth: {
      role: [PERMISSIONS.SOURCE_DOWNLOAD],
      doc: [PERMISSIONS.DOC_DOWNLOAD_COPY],
      other: ['len-more']
    }
  },
  {
    label: '内部协作',
    key: 'shareTo',
    myIcon: 'fenxiang-copy',
    range: [
      DropDownType.SOURCE,
      DropDownType.TREE_SOURCE,
      DropDownType.FILE_TYPE_SOURCE
    ],
    auth: {
      role: [PERMISSIONS.SOURCE_SHARE],
      doc: [PERMISSIONS.DOC_SHARE],
      other: ['len-1', 'isfile']
    }
  },
  {
    label: '外链分享',
    key: 'link',
    myIcon: 'zhuanfa2-copy',
    range: [
      DropDownType.SOURCE,
      DropDownType.TREE_SOURCE,
      DropDownType.FILE_TYPE_SOURCE
    ],
    auth: {
      role: [PERMISSIONS.SOURCE_SHARELINK],
      doc: [PERMISSIONS.DOC_SHARE],
      other: ['len-1']
    }
  },
  {
    type: 'divider',
    key: 'd4',
    needKey: ['download', 'shareTo', 'link']
  },
  {
    label: '复制',
    key: 'copy',
    myIcon: 'fuzhi1',
    range: [
      DropDownType.SOURCE,
      DropDownType.TREE_SOURCE,
      DropDownType.FILE_TYPE_SOURCE
    ],
    auth: {
      role: [PERMISSIONS.SOURCE_MOVE],
      doc: [PERMISSIONS.DOC_DOWNLOAD_COPY]
    }
  },
  {
    label: '剪切',
    key: 'cut',
    myIcon: 'jianqie',
    range: [
      DropDownType.SOURCE,
      DropDownType.TREE_SOURCE,
      DropDownType.FILE_TYPE_SOURCE
    ],
    auth: {
      role: [PERMISSIONS.SOURCE_MOVE],
      doc: [PERMISSIONS.DOC_REMOVE],
      other: ['len-more']
    }
  },
  {
    label: '重命名',
    key: 'rename',
    myIcon: 'zhongmingming',
    range: [
      DropDownType.SOURCE,
      DropDownType.TREE_SOURCE,
      DropDownType.FILE_TYPE_SOURCE
    ],
    auth: {
      role: [PERMISSIONS.SOURCE_EDIT],
      doc: [PERMISSIONS.DOC_EDIT],
      other: ['len-1']
    }
  },
  {
    label: '删除',
    key: 'bin',
    myIcon: 'chacha1',
    range: [
      DropDownType.SOURCE,
      DropDownType.TREE_SOURCE,
      DropDownType.FILE_TYPE_SOURCE
    ],
    auth: {
      role: [PERMISSIONS.SOURCE_REMOVE],
      doc: [PERMISSIONS.DOC_REMOVE],
      other: ['len-more']
    }
  },
  {
    type: 'divider',
    key: 'd5',
    needKey: ['copy', 'cut', 'rename', 'bin']
  },

  // 回收站相关的
  {
    label: '还原',
    key: 'recycle',
    myIcon: 'huanyuan',
    range: [DropDownType.BIN_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_REMOVE],
      doc: [PERMISSIONS.DOC_REMOVE],
      other: ['len-more']
    }
  },
  {
    label: '彻底删除',
    key: 'del-complete',
    myIcon: 'chacha1',
    range: [DropDownType.BIN_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_REMOVE],
      doc: [PERMISSIONS.DOC_REMOVE],
      other: ['len-more']
    }
  },

  {
    label: '全部还原',
    key: 'all-recycle',
    myIcon: 'huanyuan',
    range: [DropDownType.BIN_OUT],
    auth: {
      role: [PERMISSIONS.SOURCE_REMOVE],
      doc: [PERMISSIONS.DOC_REMOVE],
      other: []
    }
  },
  {
    label: '清空回收站',
    key: 'all-del-complete',
    myIcon: 'chacha1',
    range: [DropDownType.BIN_OUT, DropDownType.TREE_BIN],
    auth: {
      role: [PERMISSIONS.SOURCE_REMOVE],
      doc: [PERMISSIONS.DOC_REMOVE],
      other: []
    }
  },

  {
    type: 'divider',
    key: 'd7',
    needKey: ['recycle', 'del-complete', 'all-recycle', 'all-del-complete']
  },

  // 外链分享相关的
  {
    label: '上层文件夹显示',
    key: 'parent-folder-show',
    myIcon: 'wenjianjia2',
    range: [DropDownType.LINK_SOURCE, DropDownType.SHARETO_SOURCE],
    auth: {
      role: [],
      doc: [],
      other: ['len-1']
    }
  },
  {
    label: '打开共享页面',
    key: 'link-open',
    myIcon: 'zhuanfa1',
    range: [DropDownType.LINK_SOURCE],
    auth: {
      role: [],
      doc: [],
      other: ['len-1']
    }
  },
  {
    label: '编辑外链分享',
    key: 'share-link-edit',
    myIcon: 'zhuanfa2-copy',
    range: [DropDownType.LINK_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_SHARELINK],
      doc: [PERMISSIONS.DOC_SHARE],
      other: ['len-1']
    }
  },

  {
    type: 'divider',
    key: 'd8',
    needKey: ['parent-folder-show', 'link-open', 'link-edit', 'shareTo-edit']
  },
  {
    label: '取消外链分享',
    key: 'share-link-close',
    myIcon: 'chacha1',
    range: [DropDownType.LINK_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_SHARELINK],
      doc: [PERMISSIONS.DOC_SHARE],
      other: ['len-more']
    }
  },

  // 协作分享相关的
  {
    label: '编辑协作分享',
    key: 'share-to-edit',
    myIcon: 'fenxiang-copy',
    range: [DropDownType.SHARETO_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_SHARE],
      doc: [PERMISSIONS.DOC_SHARE],
      other: ['len-1']
    }
  },
  {
    label: '取消协作分享',
    key: 'share-to-close',
    myIcon: 'chacha1',
    range: [DropDownType.SHARETO_SOURCE],
    auth: {
      role: [PERMISSIONS.SOURCE_SHARE],
      doc: [PERMISSIONS.DOC_SHARE],
      other: ['len-more']
    }
  },

  {
    type: 'divider',
    key: 'd9',
    needKey: ['shareTo-close', 'link-close']
  },

  {
    label: '查看',
    key: 'view-model',
    range: [
      DropDownType.BIN_OUT,
      DropDownType.FILE_TYPE_OUT,
      DropDownType.SOURCE_OUT,
      DropDownType.SHARETO_OUT,
      DropDownType.LINK_OUT,
      DropDownType.LINK_DESC_OUT
    ],
    myIcon: 'shitumoshi-liebiao',
    children: [
      {
        label: '列表查看',
        key: 'out-view-list',
        myIcon: 'shitumoshi-liebiao'
      },
      {
        label: '图标查看',
        key: 'out-view-grid',
        myIcon: 'shitumoshi'
      }
    ]
  },
  {
    type: 'divider',
    key: 'd6',
    needKey: ['view-model']
  },

  {
    label: '权限设置',
    key: 'permission',
    myIcon: 'yewuquanxian',
    range: [DropDownType.SOURCE_OUT, DropDownType.TREE_SOURCE],
    auth: {
      role: [PERMISSIONS.ADMIN_MEMBER_AUTH_MANAGE],
      doc: [PERMISSIONS.DOC_MANAGE],
      other: ['dep-source'] // 需要为部门文件夹
    }
  },

  // 主要是页面更多，前进，后退
  {
    label: '更多',
    key: 'out-more',
    myIcon: 'gengduo1',
    range: [
      DropDownType.BIN_OUT,
      DropDownType.FILE_TYPE_OUT,
      DropDownType.SOURCE_OUT,
      DropDownType.SHARETO_OUT,
      DropDownType.LINK_OUT,
      DropDownType.LINK_DESC_OUT
    ],
    auth: {
      other: ['out-more']
    },
    children: [
      {
        label: '前进',
        key: 'out-more-forward',
        myIcon: 'qianjin',
        disabled: false
      },
      {
        label: '后退',
        key: 'out-more-back',
        myIcon: 'houtui',
        disabled: false
      }
    ]
  },
  {
    label: '保存到网盘',
    key: 'save-to-pan',
    myIcon: 'baocundaowangpan',
    range: [DropDownType.TREE_LINK_DESC, DropDownType.LINK_DESC],
    auth: {
      role: [PERMISSIONS.SOURCE_MOVE],
      doc: [PERMISSIONS.DOC_DOWNLOAD_COPY],
      other: []
    }
  },
  {
    label: '属性',
    key: 'desc',
    myIcon: 'jinggao',
    range: [
      DropDownType.SOURCE,
      DropDownType.SHARETO_OUT,
      DropDownType.FILE_TYPE_SOURCE,
      DropDownType.LINK_SOURCE,
      DropDownType.SHARETO_SOURCE,
      DropDownType.BIN_SOURCE,
      DropDownType.TREE_SOURCE,
      DropDownType.TREE_LINK_DESC,
      DropDownType.LINK_DESC,
      DropDownType.LINK_DESC_OUT
    ],
    auth: {
      role: [PERMISSIONS.SOURCE_VIEW],
      doc: [PERMISSIONS.DOC_VIEW],
      other: ['len-1']
    }
  }
]

// navtype到当前右键菜单range的映射
const navTypeRangeArr = [
  {
    navType: navTypeList.SOURCE,
    range: DropDownType.SOURCE,
    outRange: DropDownType.SOURCE_OUT
  },
  {
    navType: navTypeList.DEP,
    range: DropDownType.SOURCE,
    outRange: DropDownType.SOURCE_OUT
  },
  {
    navType: navTypeList.FILE_TYPE,
    range: DropDownType.FILE_TYPE_SOURCE,
    outRange: DropDownType.FILE_TYPE_OUT
  },
  {
    navType: navTypeList.USER_RECYCLE,
    range: DropDownType.BIN_SOURCE,
    outRange: DropDownType.BIN_OUT
  },
  {
    navType: navTypeList.USER_SHARE_LINK,
    range: DropDownType.LINK_SOURCE,
    outRange: DropDownType.LINK_OUT
  },
  {
    navType: navTypeList.USER_SHARE,
    range: DropDownType.SHARETO_SOURCE,
    outRange: DropDownType.SHARETO_OUT
  },
  {
    navType: navTypeList.SHARE_TO_ME,
    range: DropDownType.SOURCE,
    outRange: DropDownType.SOURCE_OUT
  },
  {
    navType: navTypeList.USER_FAV,
    range: DropDownType.SOURCE,
    outRange: DropDownType.SOURCE_OUT
  },
  {
    navType: navTypeList.LINK_SHARE_DESC,
    range: DropDownType.LINK_DESC,
    outRange: DropDownType.LINK_DESC_OUT
  }
]
export const navTypeToRange = (navType: string) => {
  console.log(navType)

  const res = navTypeRangeArr.find((item) => item.navType === navType)
  if (!res) {
    return {
      range: '',
      outRange: '',
      navType: ''
    }
  }
  return res
}
